/*
 * @Description: 
 * @Author: 赵大壮
 * @Date: 2021-12-06 17:19:11
 * @LastEditTime: 2021-12-30 15:33:48
 * @LastEditors: 张澜馨
 */
import { Component, Vue, Inject } from "vue-property-decorator";
import DZUserService from "../service/DZUserService";


@Component
export default class Index extends Vue {


    dZModelUser = new DZUserService();
    remember_pwd = false;

    created() {
    }

    mounted() {
        var rememberPwd = window.localStorage.getItem("rememberPwd");
        if(rememberPwd){
            let remember_pwd_info = JSON.parse(rememberPwd);
            this.remember_pwd = true;
            this.dZModelUser.s_username = remember_pwd_info.s_username ?? '';
            this.dZModelUser.s_password = remember_pwd_info.s_password ?? '';
        }
    }

    beforeDestroy() {

    }

    /**
     * 登录方法
     */
    doLogin() {
        this.dZModelUser.doLogin((data) => {
            this.$store.commit("SET_USER", data)
            this.$store.state.user.saveUserData(data);
            if(this.remember_pwd){
                let remember_pwd_info = {
                    s_username: this.dZModelUser.s_username,
                    s_password: this.dZModelUser.s_password,
                }
                window.localStorage.setItem("rememberPwd",JSON.stringify(remember_pwd_info));
            }
            else{ 
                window.localStorage.removeItem("rememberPwd");
            }
            this.$router.push({ path: '/' });
        })
    }

}